package com.gaofeng.customviewdemo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.gaofeng.customviewdemo.databinding.ActivityShimmerBinding
import com.romainpiel.shimmer.Shimmer
import com.romainpiel.shimmer.ShimmerTextView

class ShimmerActivity : AppCompatActivity() {

    private lateinit var binding: ActivityShimmerBinding
    private lateinit var tv: ShimmerTextView
    private var shimmer: Shimmer? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityShimmerBinding.inflate(layoutInflater)
        val rootView = binding.root
        setContentView(rootView)
        tv = binding.shimmerTv
        binding.btnOpenAnimator.setOnClickListener {
            if (shimmer != null && shimmer!!.isAnimating) {
                shimmer?.cancel()
            } else {
                shimmer = Shimmer()
                shimmer?.start<ShimmerTextView>(tv)
            }
        }
    }
}